package com.list88zhu.android.sunflower.algorithm;

/**
 * <pre><code>
 *
 *  </code></pre>
 *
 * @author zhuyingming@qmtv.com
 * @date 2018/9/19
 */
public class BalanceTree {




    private static boolean balance(Node node) {
        if (node == null) { return true; }
        int leftHight = getHeight(node.left);
        int rightHight = getHeight(node.right);
        return Math.abs(leftHight - rightHight) <= 1 && balance(node.left) && balance(node.right);
    }

    private static int getHeight(Node node) {
        if (node == null) { return 0; }
        int leftH = getHeight(node.left);
        int rightH = getHeight(node.right);
        return 1 + leftH > rightH ? leftH : rightH;
    }



    class Node {
        public int data;
        public Node left;
        public Node right;
    }

}
